package learning.directory.Work.排序.Nf;

import java.util.Arrays;

/**
 * @author NIEF
 */
public class QuickSortDay2 {

    public static void main(String[] args) {
        int[] arrSort = {49, 38, 65, 97, 23, 22, 76, 1};
        quickSort(arrSort);
        System.out.println(Arrays.toString(arrSort));
    }


    private static void quickSort(int[] array, int low, int high) {
        if (low >= high) {
            return;
        }
        int i = low, j = high, index = array[i];
        while (i < j) {
            while (i < j && array[j] >= index) {
                j--;
            }
            if (i < j) {
                array[i++] = array[j];
            }
            while (i < j && array[i] < index) {
                i++;
            }
            if (i < j) {
                array[j--] = array[i];
            }
        }
        array[i] = index;
        quickSort(array, low, i - 1);
        quickSort(array, i + 1, high);
    }

    public static void quickSort(int[] array) {
        if (array == null || array.length == 0) {
            return;
        }
        quickSort(array, 0, array.length - 1);
    }

}